//
//  GSSearch_threeImageCell.m
//  GameSky
//
//  Created by lanou on 16/1/15.
//  Copyright © 2016年 NiRongfei. All rights reserved.
//

#import "GSSearch_threeImageCell.h"

@implementation GSSearch_threeImageCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // 夜间模式
        self.dk_backgroundColorPicker = DKColorWithRGB(0xffffff, 0x343434);
        
        CGFloat height = kScreenHeight / 4;
// 标题
        self.titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(8, 0, kScreenWidth - 16, height / 4)];
        _titleLabel.font = [UIFont systemFontOfSize:15];
        [self.contentView addSubview:self.titleLabel];
// 图片
        CGFloat width = (kScreenWidth - 8 * 4) / 3;
        for (int i = 0; i < 3; i++) {
            UIImageView *imageV = [[UIImageView alloc] initWithFrame:CGRectMake(8 + (i  * (width + 8)), _titleLabel.bottom, width, height / 2)];
            imageV.tag = 100 + i;
            imageV.backgroundColor = [UIColor yellowColor];
            [self.contentView addSubview:imageV];
        }
        // 关联属性, 方便赋值
        self.leftPictureImageV = (UIImageView *)[self.contentView viewWithTag:100];
        self.middlePictureImageV = (UIImageView *)[self.contentView viewWithTag:101];
        self.rightPictureImageV = (UIImageView *)[self.contentView viewWithTag:102];

// 评论
        self.commentsCountLabel = [[UILabel alloc] initWithFrame:CGRectMake(8, _leftPictureImageV.bottom + 8, kScreenWidth - 16 - 29 - 16, height - _leftPictureImageV.bottom - 8 - 8)];
        _commentsCountLabel.textAlignment = NSTextAlignmentRight;
        _commentsCountLabel.font = [UIFont systemFontOfSize:14];
        [self.contentView addSubview:_commentsCountLabel];
        
// 标签 图片
        self.badgesImageV = [[UIImageView alloc] initWithFrame:CGRectMake(self.commentsCountLabel.right + 8, self.commentsCountLabel.top, 29, self.commentsCountLabel.height)];
        _badgesImageV.backgroundColor = [UIColor purpleColor];
        [self.contentView addSubview:self.badgesImageV];

    }
    return self;
}
#pragma mark-----------------重写setter方法---------------
- (void)setModel:(GSSearch_Model *)model{
    _model = model;
// 各个控件赋值
    _titleLabel.text = model.title;
    [_leftPictureImageV sd_setImageWithURL:[NSURL URLWithString:model.thumbnailURLs[0]] placeholderImage:nil];
    [_middlePictureImageV sd_setImageWithURL:[NSURL URLWithString:model.thumbnailURLs[1]] placeholderImage:nil];
    [_rightPictureImageV sd_setImageWithURL:[NSURL URLWithString:model.thumbnailURLs[2]] placeholderImage:nil];
// 如果没有 标签, 则应该 重新给 评论label frame
    if (model.badges == nil || model.badges.count == 0) {
        _badgesImageV.alpha = 0;
        CGRect temp = _commentsCountLabel.frame;
        temp.size.width = kScreenWidth - 16;
        _commentsCountLabel.frame = temp;
    }else{
        _badgesImageV.alpha = 1;

        CGRect temp = _commentsCountLabel.frame;
        temp.size.width = kScreenWidth - 16 - 29 - 16;
        _commentsCountLabel.frame = temp;
    
    }
    _commentsCountLabel.text = [NSString stringWithFormat:@"%@评论",model.commentsCount];
}
#pragma mark---------------------------------------------
- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
